package com.example.demo08;

import android.content.Context;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

public class DrawPage extends Fragment {

	class MyView extends View {
				public MyView(Context context) {
			super(context);
		}

		float dx, dy;
		long t, t1;
		@Override
		public boolean onTouchEvent(MotionEvent event) {
			float x = event.getRawX();
			float y = event.getRawY();
			
			switch(event.getAction()) {
			case MotionEvent.ACTION_DOWN:
				System.out.println("down " + x + " " + y);
				t = SystemClock.currentThreadTimeMillis();
				dx = x;
				dy = y;
				break;
			case MotionEvent.ACTION_MOVE:
				t1 = SystemClock.currentThreadTimeMillis();
				System.out.println("move " + dx + " " + dy + " -> " + x + " " + y + " " + (t1-t));
				t = t1;
				dx = x;
				dy = y;
				break;
			case MotionEvent.ACTION_UP:
				System.out.println("up " + x + " " + y);
//				performClick();
				break;
			}
			
			return true;
		}

	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		return new MyView(getActivity());
	}
}
